import org.I0Itec.zkclient.ZkClient;

import java.io.IOException;
import java.sql.SQLException;
import java.util.Properties;

public class Test {

    public static void main(String[] args) throws Exception {

        Publisher publisher = new Publisher();
        String info = "driverClassName=com.mysql.cj.jdbc.Driver\n" +
                "url=jdbc:mysql://linux03:3306/azkaban?useUnicode=true&characterEncoding=utf8&useSSL=false\n" +
                "username=hive\n" +
                "password=12345678\n" +
                "initCount=5\n" +
                "maxCount=10\n" +
                "currentCount=5";
        publisher.publish(info);

        ZkClient zkClient = new ZkClient("linux01:2181,linux02:2181,linux03:2181");
        String cfg = zkClient.readData("/zktask/dblink", true);
        Properties pro = new Properties();
//        //这里要写参数
//        pro.setProperty("driverClassName","com.mysql.cj.jdbc.Driver");
//        pro.setProperty("url","jdbc:mysql://linux03:3306/azkaban?useUnicode=true&characterEncoding=utf8&useSSL=false");
//        pro.setProperty("username","hive");
//        pro.setProperty("password","12345678");
//        pro.setProperty("initCount","5");
//        pro.setProperty("maxCount","10");
//        pro.setProperty("currentCount","5");

        Utils.loadData(pro, cfg);
        // 创建数据库连接池
        Utils.createDbPool(pro);
        // 监听节点数据的变化
        Listener.monitor();

        //改变数据库连接信息
        String newInfo = "driverClassName=com.mysql.cj.jdbc.Driver\n" +
                "url=jdbc:mysql://linux03:3306/azkaban?useUnicode=true&characterEncoding=utf8&useSSL=false\n" +
                "username=root\n" +
                "password=12345678\n" +
                "initCount=10\n" +
                "maxCount=20\n" +
                "currentCount=10";
        publisher.publish(newInfo);
        Thread.sleep(5000);
        //删除节点
        publisher.delete();
        Thread.sleep(1000);
    }
}
